package com.example.web.service.cabinetstatus.impl;

import com.example.web.service.TimeIteratorNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.regex.Pattern;

@Slf4j
@Order(2)
@Component
public class TimestampIteratorNodeImpl extends TimeIteratorNode {
    @Override
    public boolean condition(String timeStr) {
        log.info("check timestamp");
        String pattern = "^\\d{1,10}$";
        return Pattern.matches(pattern, timeStr);

    }

    @Override
    public LocalDateTime parse(String timeStr) {
        log.info("use timestamp");
        return Timestamp.valueOf(timeStr).toLocalDateTime();
    }
}
